package com.computer.network.controller;

import com.computer.network.service.PaperService;
import com.computer.network.entity.vo.PaperVO;
import com.computer.network.entity.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/paper")
public class PaperController {
    @Autowired
    PaperService paperService;

    /**
     * 新增问卷
     * @param paperVO
     * @return
     */
    @PostMapping("/addPaper")
    public ResponseVO addPaper(@RequestBody PaperVO paperVO){
        return paperService.addPaper(paperVO);
    }

    /**
     * 更新问卷
     * @param paperVO
     * @return
     */
    @PostMapping("/updatePaper")
    public ResponseVO updatePaper(@RequestBody PaperVO paperVO){
        return paperService.updatePaper(paperVO);
    }

    /**
     * 删除问卷
     * @param paperId
     * @return
     */
    @GetMapping("/{paperId}/deletePaper")
    public ResponseVO invalidatePaper(@PathVariable Integer paperId){
        return paperService.deletePaper(paperId);
    }

    /**
     * 获取用户的问卷列表
     * @param userId
     * @return
     */
    @GetMapping("/{userId}/getUserPapers")
    public ResponseVO getUserPapers(@PathVariable Integer userId){
        return paperService.getUserPapers(userId);
    }

    /**
     * 实时检查问卷状态，开始和截止
     * SpringTask定时任务，每分钟执行一次
     * @param paperId
     * @return
     */
    @GetMapping("/{paperId}/checkPaper")
    public ResponseVO checkPaper(@PathVariable Integer paperId){
        return paperService.checkPaper(paperId);
    }

    /**
     * 发布问卷
     * @param paperId
     * @return
     */
    @GetMapping("/{paperId}/reviewPaper")
    public ResponseVO reviewPaper(@PathVariable Integer paperId){
        return paperService.reviewPaper(paperId);
    }
}
